$(function () {
    var memberid = null;
    var registerPage = function () {
        this.init();
    };
    registerPage.prototype = {
        init: function () {
            this.initData();
            this.bindEvent();
        },
        initData: function () {
            memberid = getUrlParam("memberId");
        },
        bindEvent: function () {

            //点击后退
            $("#back").on("tap", function () {
                back();
            });

            //点击登陆
            $("#login").on("tap", function () {
                redirect('login.html');
            });

            //点击获取验证码
            $("#getVcode").on("tap", function () {
                change_code(this, $("#phone"), SMS_TYPE.verify);
            });

            $("#phone,#vcode,#password,#confirmPassword").on("input", function () {

                if ("" != $("#phone").val() &&
                    "" != $("#vcode").val() &&
                    "" != $("#password").val() &&
                    "" != $("#confirmPassword").val()) {
                    $("#register").addClass("liang");

                    //点击注册
                    $("#register").unbind().on("tap", function () {
                        if (!isTelephone($("#phone").val())) {
                            $.alert("请填写正确的手机号");
                            return false;
                        }
                        if ($("#password").val() != $("#confirmPassword").val()) {
                            $.alert("两次填写的密码不一致");
                            return false;
                        }


                        $.getScript("http://pv.sohu.com/cityjson?ie=utf-8").done(function () {
                            var postData = {
                                "phone": $("#phone").val(),
                                "password": $("#password").val(),
                                "ip": "115.206.119.131", // returnCitySN.cip,
                                "type": 3,
                                "vcode": $("#vcode").val()
                            };
                            if (memberid) {
                                postData.referrer = memberid;
                                postData.from = "Vaecn";
                            }
                            $.ajax({
                                type: "POST",
                                url: CONFIG_MANAGER.RequstUrl + "v1/account/register",
                                async: true,
                                data: postData
                            }).always(function (data) {
                                if (data.status && 400 == data.status) {
                                    $.alert(JSON.parse(data.responseText).Message);
                                } else {
                                    if (data.id) {
                                        $.alert("注册成功", function () {
                                            redirect("registerSucc.html");
                                            return false;
                                        });
                                    }
                                }
                            });
                        });
                    });


                } else {

                    $("#register").unbind().removeClass("liang");

                }

            })


        },


    };

    var page = new registerPage();

})
